<?php
declare (strict_types = 1);

namespace app\api\controller;
use app\api\model\ComAmounts;
use app\api\model\GroupMaster;
use app\api\model\GroupMasterGrade;
use think\Exception;
use think\facade\Config;
use think\facade\Request;

class GroupMasters
{
    /*
     * 生成佣金记录
     */
    public function GroupSelect()
    {
        //模拟数据
        try {
            $order = ['id'=>2,'is_o'=>1,'t_id'=>2,'price'=>2000];
            //判断模拟数据是否有值
            if($order['is_o']==1){
                $t_id = $order['t_id'];
                //查询团长表数据
                $data = GroupMaster::where('id',$t_id)->find();
                //查询团长等级表数据
                $datas = GroupMasterGrade::where('id',$data['user_id'])->find();
//            return json(['code'=>200,'msg'=>'查询成功','data'=>$datas]);
                //计算佣金金额
                $commission = $order['price']*($datas['reward_ratio']*0.01);
                //如果有，则进行添加到佣金记录表
                $success = ComAmounts::create([
                    'member_nickname'=>$t_id,
                    'commission_amount'=>$commission
                ]);
                //判断佣金是否添加成功
                if($success){
                    //添加成功返回
                    return json(['code'=>'200','msg'=>'添加佣金成功','data'=>$success]);
                }else{
                    //添加失败返回
                    return json(['code'=>'400','msg'=>'添加佣金失败','data'=>'']);
                }
            }else{
                return json(['code'=>'40004','msg'=>'请传输正确参数','data'=>'']);
            }
        }catch (Exception $exception){
            echo "异常捕获".$exception;
        }

    }

    /**
     * 测试全局常量
     */
    public function config()
    {
        $data=Request::get('status');
        $testConfig = config('status.profile.bank.status');
        if($data==$testConfig){
            echo "111";
        }else{
            echo "222";
        }
    }

}
